package com.augurit.gzcgwsp.jzfqwczzpfsn.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.common.convert.WfBusClientBaseInfoConvertor;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnJzfqwczzCsForm;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnJzfqwczzXckcForm;
import com.augurit.gzcgwsp.jzfqwczzpfsn.entity.YwYnJzfqwczzPfsn;
import com.augurit.gzcgwsp.jzfqwczzpfsn.web.form.YwYnJzfqwczzPfsnForm;
import com.augurit.gzcgwsp.lhsp.web.form.LhspSendItemNoticeForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwYnJzfqwczzPfsnForFx;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxTwoForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComYsgsForm;

public class YwYnJzfqwczzPfsnConvert {
	
	public static void convertSendItemNoticeFormToForm(LhspSendItemNoticeForm sendItemNoticeForm,YwYnJzfqwczzPfsnForm form) {
        Long id = form.getId();
		new DozerBeanMapper().map(sendItemNoticeForm, form);
		form.setId(id);
    }
	public static YwYnJzfqwczzPfsnForm convertVoToForm(YwYnJzfqwczzPfsn entity) {
		if(entity != null) {
			YwYnJzfqwczzPfsnForm form = new DozerBeanMapper().map(entity, YwYnJzfqwczzPfsnForm.class);
			
			WfBusClientBaseInfoConvertor.convertVoToForm(entity, form);
			
			return form;
		}else
			return null;
	}
	
	public static void convertFormToXckcForm(YwYnJzfqwczzPfsnForm form, YwYnJzfqwczzXckcForm ywYnJzfqwczzXckcForm) {
        if (form == null) return;
        if (ywYnJzfqwczzXckcForm == null) ywYnJzfqwczzXckcForm = new YwYnJzfqwczzXckcForm();
        
        new DozerBeanMapper().map(form, ywYnJzfqwczzXckcForm);
        ywYnJzfqwczzXckcForm.setId(form.getXckcid());
    }
	
	public static void convertFormToCsForm(YwYnJzfqwczzPfsnForm form, YwYnJzfqwczzCsForm ywYnJzfqwczzCsForm) {
        if (form == null) return;
        if (ywYnJzfqwczzCsForm == null) ywYnJzfqwczzCsForm = new YwYnJzfqwczzCsForm();
        
        new DozerBeanMapper().map(form, ywYnJzfqwczzCsForm);
        ywYnJzfqwczzCsForm.setId(form.getCsid());
    }
	
	public static List<YwYnJzfqwczzPfsnForm> convertVoListToFormList(List<YwYnJzfqwczzPfsn> YwYnJzfqwczzPfsnList) {
		if(YwYnJzfqwczzPfsnList != null && YwYnJzfqwczzPfsnList.size() > 0) {
			List<YwYnJzfqwczzPfsnForm> YwYnJzfqwczzPfsnFormList = new ArrayList();
			for(int i=0; i<YwYnJzfqwczzPfsnList.size(); i++) {
				YwYnJzfqwczzPfsnFormList.add(convertVoToForm(YwYnJzfqwczzPfsnList.get(i)));
			}
			return YwYnJzfqwczzPfsnFormList;
		}
		return null;
	}
	public static void convertFormToQyxxForm(YwYnJzfqwczzPfsnForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();
        new DozerBeanMapper().map(form, qyxxForm);
        qyxxForm.setId(form.getQyid());
        
        if(StringUtils.isNotBlank(form.getJsdwDz())){
        	qyxxForm.setAddress(form.getJsdwDz());
        }
        if(StringUtils.isNotBlank(form.getJsdwLxr())){
        	qyxxForm.setYwlxr(form.getJsdwLxr());
        }
        if(StringUtils.isNotBlank(form.getJsdwLxrLxdh())){
        	qyxxForm.setYwlxrtel(form.getJsdwLxrLxdh());
        }
        if(form.getSqDate() != null){
        	qyxxForm.setSqrq(form.getSqDate());
        }
    }
	
	public static void convertFormToQyxxTwoForm(YwYnJzfqwczzPfsnForm form, YwComQyxxTwoForm ywComQyxxTwoForm) {
        if (form == null) return;
        if (ywComQyxxTwoForm == null) ywComQyxxTwoForm = new YwComQyxxTwoForm();
        
        new DozerBeanMapper().map(form, ywComQyxxTwoForm);
        if(StringUtils.isNotBlank(form.getQybhTwo())){
        	ywComQyxxTwoForm.setId(Long.parseLong(form.getQybhTwo()));
        }else{
        	ywComQyxxTwoForm.setId(null);
        }
        if(StringUtils.isNotBlank(form.getSgdwGz())){
        	ywComQyxxTwoForm.setSqdwTwo(form.getSgdwGz());
        }
        if(StringUtils.isNotBlank(form.getSgdwXmjl())){
        	ywComQyxxTwoForm.setXmjlTwo(form.getSgdwXmjl());
        }
        if(StringUtils.isNotBlank(form.getSgdwXmjlLxdh())){
        	ywComQyxxTwoForm.setXmjlTelTwo(form.getSgdwXmjlLxdh());
        }
        if(StringUtils.isNotBlank(form.getSgdwLxr())){
        	ywComQyxxTwoForm.setLxrTwo(form.getSgdwLxr());
        }
        if(StringUtils.isNotBlank(form.getSgdwLxrLxdh())){
        	ywComQyxxTwoForm.setTelTwo(form.getSgdwLxrLxdh());
        }
        if(form.getSqDate() != null){
        	ywComQyxxTwoForm.setSqrqTwo(form.getSqDate());
        }
	}
	
	public static void convertFormToYsgsForm(YwYnJzfqwczzPfsnForm form, YwComYsgsForm ywComYsgsForm) {
        if (form == null) return;
        if (ywComYsgsForm == null) ywComYsgsForm = new YwComYsgsForm();
        
        new DozerBeanMapper().map(form, ywComYsgsForm);
        if(StringUtils.isNotBlank(form.getYsgsId())){
        	ywComYsgsForm.setId(Long.parseLong(form.getYsgsId()));
        }else{
        	ywComYsgsForm.setId(null);
        }
        if(StringUtils.isNotBlank(form.getYsgs())){
        	ywComYsgsForm.setYsgs(form.getYsgs());
        }
        if(StringUtils.isNotBlank(form.getYsgsLxr())){
        	ywComYsgsForm.setYsgsLxr(form.getYsgsLxr());
        }
        if(StringUtils.isNotBlank(form.getYsgsLxrLxdh())){
        	ywComYsgsForm.setYsgsLxrLxdh(form.getYsgsLxrLxdh());
        }
        if(form.getSqDate() != null){
        	ywComYsgsForm.setSqrq(form.getSqDate());
        }
	}
	
	public static void convertFormToVo(YwYnJzfqwczzPfsnForm form, YwYnJzfqwczzPfsn entity) {
        if (form == null) return;
        if (entity == null) entity = new YwYnJzfqwczzPfsn();
        
        new DozerBeanMapper().map(form, entity);
    }
	
	public static List<Map> convertVoListToMapList(List<YwYnJzfqwczzPfsn> ywYnJzfqwczcJbxxList) {
		if(ywYnJzfqwczcJbxxList != null && ywYnJzfqwczcJbxxList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<ywYnJzfqwczcJbxxList.size(); i++) {
				YwYnJzfqwczzPfsn entity = ywYnJzfqwczcJbxxList.get(i);
				Map<String, String> map = new HashMap();
				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("acceptNo", entity.getAcceptNo());
				map.put("sqDate", DateUtils.dateTimeToString(entity.getSqDate(), "yyyy-MM-dd"));
				map.put("qymc", entity.getQymc());
				map.put("dbrxm", entity.getDbrxm());
				map.put("dbrdh", entity.getDbrdh());
				map.put("address", entity.getAddress());
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<YwYnJzfqwczzPfsn> convertFormListToVoList(List<YwYnJzfqwczzPfsnForm> ywYnJzfqwczcJbxxFormList) {
		if(ywYnJzfqwczcJbxxFormList != null && ywYnJzfqwczcJbxxFormList.size() > 0) {
			List<YwYnJzfqwczzPfsn> ywYnJzfqwczcJbxxList = new ArrayList();
			for(int i=0; i<ywYnJzfqwczcJbxxFormList.size(); i++) {
				YwYnJzfqwczzPfsn YwYnJzfqwczzPfsn = new YwYnJzfqwczzPfsn();
				convertFormToVo(ywYnJzfqwczcJbxxFormList.get(i), YwYnJzfqwczzPfsn);
				ywYnJzfqwczcJbxxList.add(YwYnJzfqwczzPfsn);
			}
			return ywYnJzfqwczcJbxxList;
		}
		return null;
	}
	
	public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, YwYnJzfqwczzPfsnForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new YwYnJzfqwczzPfsnForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQyid(qyxxForm.getId());
        
        if(StringUtils.isNotBlank(qyxxForm.getAddress())){
        	form.setJsdwDz(qyxxForm.getAddress());
        }
        if(StringUtils.isNotBlank(qyxxForm.getYwlxr())){
        	form.setJsdwLxr(qyxxForm.getYwlxr());
        }
        if(StringUtils.isNotBlank(qyxxForm.getYwlxrtel())){
        	form.setJsdwLxrLxdh(qyxxForm.getYwlxrtel());
        }
    }
	
	public static void convertXckcFormToForm(YwYnJzfqwczzXckcForm ywYnJzfqwczzXckcForm, YwYnJzfqwczzPfsnForm form) {
        if (ywYnJzfqwczzXckcForm == null) return;
        if (form == null) form = new YwYnJzfqwczzPfsnForm();
        
        new DozerBeanMapper().map(ywYnJzfqwczzXckcForm, form);
        form.setXckcid(ywYnJzfqwczzXckcForm.getId());
    }
	
	public static void convertCsFormToForm(YwYnJzfqwczzCsForm ywYnJzfqwczzCsForm, YwYnJzfqwczzPfsnForm form) {
        if (ywYnJzfqwczzCsForm == null) return;
        if (form == null) form = new YwYnJzfqwczzPfsnForm();
        
        new DozerBeanMapper().map(ywYnJzfqwczzCsForm, form);
        form.setCsid(ywYnJzfqwczzCsForm.getId());
    }
	
	public static void convertFormToYwYnJzfqwczzPfsnForFx(YwYnJzfqwczzPfsnForm form, YwYnJzfqwczzPfsnForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwYnJzfqwczzPfsnForFx();        
        new DozerBeanMapper().map(form, entity);
    }
}
